// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CLOUDAPPENGINE_CAETCPSERVERSOCKET_H
#define CLOUDAPPENGINE_CAETCPSERVERSOCKET_H

#include <pthread.h>
#include "../cae_socket/CaeSocket.h"
#include "../cae_socket/CaeTcpSocket.h"

class CaeTcpServerSocket : public CaeTcpSocket {
public:
    CaeTcpServerSocket(uint32_t localIp, uint16_t localPort, CaeServerService *pObject);

    CaeTcpServerSocket(uint32_t socketOption, uint32_t localIp, uint16_t localPort, CaeServerService *pObject);

    ~CaeTcpServerSocket() override;

    void NotifyServerService(CaeSocket *caeSocket);

    void SetThreadId(pthread_t threadId);

    void SetListenStatus(int status);

    int GetListenStatus() const;

    void SetServerType(ServerType type);

    ServerType GetServerType();

private:
    volatile pthread_t m_threadId;
    int m_listenStatus;
    CaeServerService *m_serverService {};
    ServerType m_serverType = ServerType::TCP;
    int CaeCreateTcpServer(uint32_t socketOption, uint32_t remoteIp, uint16_t remotePort, uint32_t localIp,
        uint16_t localPort, CaeServerService *pObject);
};

#endif // CLOUDAPPENGINE_CAETCPSERVERSOCKET_H
